package com.zmc.member.controller;

import com.zmc.common.utils.R;
import com.zmc.member.infrastructure.bean.query.ShoppingCartQuery;
import com.zmc.member.infrastructure.bean.vo.*;
import com.zmc.member.infrastructure.enums.PreOrderEnum;
import com.zmc.member.application.impl.ShoppingCartCacheApplicationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 购物车
 *
 * @author zmc
 * @email 
 * @date 2024-10-09 14:56:33
 */
@RestController
@RequestMapping("/cart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartCacheApplicationServiceImpl shoppingCartCacheApplicationService;

    /**
     * 用户登录时，合并购物车
     */
    @PostMapping("/merge")
    public R merge(@RequestBody List<ShoppingCartVo> shoppingCartVo){
        shoppingCartCacheApplicationService.merge(shoppingCartVo);
        return R.ok();
    }

    /**
     * 删除购物车
     */
    @PostMapping("/delete")
    public R delete(@RequestBody ShoppingCartItemDeleteVo vo){
        shoppingCartCacheApplicationService.delete(vo.getSkuIds());
        return R.ok();
    }

    /**
     * 加入购物车
     */
    @PostMapping("/add")
    public R add(@RequestBody ShoppingCartVo shoppingCartVo){
        shoppingCartCacheApplicationService.add(shoppingCartVo);
        return R.ok();
    }

    /**
     * 购物车列表
     */
    @PostMapping("/list")
    public R list(@RequestBody ShoppingCartQuery query){
        return R.ok(shoppingCartCacheApplicationService.shoppingCartList(query));
    }

    /**
     * 修改购物车商品, 选中状态和数量
     */
    @PostMapping("/update")
    public R update(@RequestBody ShoppingCartItemUpdateCountVo vo){
        shoppingCartCacheApplicationService.updateByCartItemId(vo);
        return R.ok();
    }

    /**
     * 修改购物车商品, 选中状态和数量
     */
    @PostMapping("/update/status")
    public R updateStatus(@RequestBody ShoppingCartSelectedVo vo){
        shoppingCartCacheApplicationService.setSelectedStatus(vo);
        return R.ok();
    }


    /**
     * 完成生单后，清除已选中购物车
     */
    @RequestMapping("/selected")
    public R clearHasSelected(){
        shoppingCartCacheApplicationService.clearHasSelected();
        return R.ok();
    }

}
